#pragma once

#include <QWidget>
#include <QMenuBar>
#include <QStatusBar>
#include <QToolBar>

class TabManager;
class DockingArea;
class DockTab;
class DockingTabWell;

namespace Ui {
class VGMainWindow;
}

/**
 * VGMainWindow - 主窗口
 * 采用类似UE4编辑器的界面布局，集成停靠系统
 */
class VGMainWindow : public QWidget
{
    Q_OBJECT

public:
    explicit VGMainWindow(QWidget *parent = nullptr);
    ~VGMainWindow();
    
    // === 停靠系统访问 ===
    TabManager* tabManager() const { return TabManagerInstance; }
    DockingArea* dockingArea() const { return DockingAreaInstance; }

public slots:
    // 主标签栏激活切换
    void onMainWellTabActivated(DockTab* tab, int index);

protected:
    void closeEvent(QCloseEvent* event) override;
    void showEvent(QShowEvent* event) override;

private slots:
    // === 菜单操作 ===
    void onNewProject();
    void onOpenProject();
    void onSaveProject();
    void onExit();
    
    // === 视图菜单 ===
    void onShowViewport();
    void onShowContentBrowser();
    void onShowWorldOutliner();
    void onShowDetailsPanel();
    void onShowOutputLog();
    
    // === 窗口菜单 ===
    void onResetLayout();
    void onSaveLayout();
    void onLoadLayout();
    
    // === 标签页事件 ===
    void onTabSpawned(DockTab* tab);
    void onTabClosed(DockTab* tab);
    
    // === 菜单显示 ===
    void onShowFileMenu();
    void onShowEditMenu();
    void onShowWindowMenu();

private:
    // === 初始化 ===
    void initializeMainWindow();
    void setupApplicationIcon();
    void setupMenuButtonIcons();
    void setupMenuBar();
    void setupToolBars();
    void setupStatusBar();
    void setupDockingSystem();
    void setupConnections();
    void setupOverlayTabAndMenuBar();
    void updateCentralContentForTab(class DockTab* tab); // 根据主标签/非主标签切换中央内容
    
    // === 标签页注册 ===
    void registerDefaultTabTypes();
    
    // === 布局管理 ===
    void createDefaultLayout();
    void createUE4LikeLayout();
    
    // === 工具函数 ===
    void updateMenuStates();
    void saveSettings();
    void loadSettings();
    void loadStyleSheet();

private:
    Ui::VGMainWindow *ui;
    
    // === 停靠系统 ===
    TabManager* TabManagerInstance;
    DockingArea* DockingAreaInstance;
    
    // === UI组件 ===
    QMenuBar* MenuBar;
    QStatusBar* StatusBar;
    QToolBar* MainToolBar;
    QToolBar* ViewToolBar;
    
    // === 动态创建的QOverlay组件 ===
    DockingTabWell* DynamicMainTabWell;
    
    // === 菜单 ===
    QMenu* FileMenu;
    QMenu* EditMenu;
    QMenu* ViewMenu;
    QMenu* WindowMenu;
    QMenu* HelpMenu;
    
    // === 动作 ===
    QAction* NewProjectAction;
    QAction* OpenProjectAction;
    QAction* SaveProjectAction;
    QAction* ExitAction;
    
    QAction* ShowViewportAction;
    QAction* ShowContentBrowserAction;
    QAction* ShowWorldOutlinerAction;
    QAction* ShowDetailsPanelAction;
    QAction* ShowOutputLogAction;
    
    QAction* ResetLayoutAction;
    QAction* SaveLayoutAction;
    QAction* LoadLayoutAction;

};
